package com.xx.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xx.entity.Employees;
import com.xx.entity.PageResult;
import com.xx.service.IEmployeesService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author AY
 * @since 2024-12-09 10:49
 */
@RestController
@RequestMapping("/employees")
@Tag(name = "员工前端控制器",description = "员工接口")
public class EmployeesController {
    @Autowired
    IEmployeesService iEmployeesService;

    // 添加员工
    @PostMapping
    public boolean save(@RequestBody Employees employees) {
        return iEmployeesService.save(employees);
    }

    // 通过ID删除员工
    @DeleteMapping("/{id}")
    public boolean delete(@PathVariable Integer id) {
        return iEmployeesService.removeById(id);
    }

    // 修改
    @PutMapping("/{id}")
    public boolean update(@PathVariable Integer id, @RequestBody Employees employees) {
        employees.setEmployeeId(id);
        return iEmployeesService.updateById(employees);
    }

    // 通过ID查询员工信息
    @GetMapping("/{id}")
    public Employees getById(@PathVariable Integer id) {
        return iEmployeesService.getById(id);
    }

    // 分页查询
    @GetMapping("/page")
    public Page<Employees> page(
            @RequestParam(defaultValue = "1") Integer current,
            @RequestParam(defaultValue = "3") Integer size) {
        Page<Employees> page = new Page<>(current, size);
        return iEmployeesService.page(page);
    }






    //分页
    @PutMapping
    @Operation(summary = "员工分页接口",description = "获取分页数据")
    public PageResult<Employees> getPage(@Parameter(name = "pageNum",description = "当前页",required = true) int pageNum,
                                         @Parameter(name = "pageSize",description = "每页条数",required = false)
                                         @RequestParam(value = "pageSize",defaultValue = "10")
                                         int pageSize){
        Page page = new Page(pageNum,pageSize);
        return iEmployeesService.getPage(page);
    }
//    //新增员工
//    @PostMapping
//    public void saveEmployee(Employees employees){
//        iEmployeesService.save(employees);
//    }
//
//    @PutMapping
//    public void updateEmployee(Employees employees){
//        iEmployeesService.updateById(employees);
//    }
//
//    @PutMapping
//    public Employees getEmployee(@PathVariable Integer id){
//        Employees employees = iEmployeesService.getById(id);
//        return iEmployeesService.getById(id);
//    }
}